<template>
  <div class="wx_content_check">
    <div class="conditions">
      <el-row>
        <el-col :span="8"><el-input v-model="wd" placeholder="请输入标题关键字搜索" @keyup.enter.native="submitSearch"></el-input></el-col>
        <el-col :span="3" style="margin-left:10px"><el-button type="primary" @click="submitSearch">搜索</el-button></el-col>
      </el-row>
      <el-row>
        <span class="label">内容性质：</span>
        <el-select v-model="attrId" placeholder="不限" clearable>
          <el-option v-for="item,n in attrs" :value="item.id" :label="item.name" :key="n.toString()"></el-option>
        </el-select>
      </el-row>
    </div>
    <el-table v-loading="tbLoading" element-loading-text="拼命加载中" :data="checkList.list" stripe class="table">
      <!-- <el-table-column type="selection"></el-table-column> -->
      <el-table-column label="消息类型" width="400">
        <template slot-scope="scope">
          <div>
            多图文({{scope.row.newsList.length}})
          </div>
          <div v-for="item,n in scope.row.newsList" class="newsItem">
            <img :src="baseUrl + '/content/source/id/'+item.sourceId" alt="" class="preview">
            <p class="content">
              [图文{{n+1}}] <a :href="`${baseUrl}/content/wxnews/preview?logicId=${scope.row.logicId}&index=${n}`" target="_blank">{{item.title}}</a>
            </p>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="username" label="提交人"></el-table-column>
      <el-table-column label="提交时间" width="200">
        <template slot-scope="scope">
          {{dateFormat(scope.row.createTime)}}
        </template>
      </el-table-column>
      <el-table-column label="审核结果" width="200"  class-name="is-center">
        <template slot-scope='scope'>
          <div v-if="scope.row.auditStatus==1">通过</div>
          <div v-else class="red">
            未通过
            <el-tooltip :content="scope.row.reason" placement="top" effect="light">
              <div class="reason">(<em>{{scope.row.reason}}</em>)</div>
            </el-tooltip>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        :current-page.sync="page"
        :page-size.sync="size"
        layout="sizes, total, prev, pager, next, jumper"
        :page-sizes="[10, 30, 50, 100]"
        :total="checkList.page.total"
        @current-change="submitSearch()"
        @size-change="handleSizeChange">
      </el-pagination>
    </div>
    <!-- 审核不通过弹层 -->
    <el-dialog :visible.sync="dialogShow" width="30%">
      <el-input v-model="reason" type="textarea" placeholder="请输入原因，不多于255字"></el-input>
      <div slot="footer">
        <el-button type="primary" @click="handleNoPass">确定</el-button>
        <el-button type="primary" @click="dialogShow=false;">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {mapActions, mapState} from 'vuex'
  import config from '@/config/env'
  export default {
    data () {
      return {
        wd: '',
        attrId: null,
        sourceType: 1,
        authStatus: null,
        page: 1,
        size: 10,
        reason: null,
        dialogShow: false,
        tbLoading: false
      }
    },
    mounted () {
      this.initPage()
    },
    computed: {
      ...mapState({
        checkList: state => state.contentManage.wxCheckList,
        attrs: state => state.contentManage.contentType
      }),
      baseUrl () {
        return config.baseUrl
      }
    },
    methods: {
      ...mapActions(['getWxCheckList', 'getContentTypes', 'setWxReleaseCheck']),
      async initPage () {
        this.getContentTypes()
        await this.submitSearch()
      },
      // 日期格式化
      dateFormat (date) {
        return this.$date.format(new Date(date), 'YYYY-MM-DD HH:mm:ss')
      },
      // 搜索
      async submitSearch () {
        this.tbLoading = true
        await this.getWxCheckList({
          wd: this.wd,
          attribute: this.attrId,
          auditStatus: 1,
          page: this.page,
          size: this.size
        })
        this.tbLoading = false
      },
      // 改变分页大小
      handleSizeChange (size) {
        this.size = size
        this.submitSearch()
      },
      // 通过审核
      async handlePass (id) {
        await this.$confirm('确认审核通过该条记录？')
        const res = await this.setWxReleaseCheck({
          auditId: id,
          auditStatus: 1
        })
        res.data.code === 1 && this.$message('成功')
        this.submitSearch()
      },
      // 不通过审核
      async handleNoPass () {
        const res = await this.setWxReleaseCheck({
          auditId: this.checkId,
          auditStatus: 2,
          reason: this.reason
        })
        res.data.code === 1 && this.$message.success(res.data.msgZ)
        this.submitSearch()
        this.dialogShow = false
      }
    }
  }
</script>
<style lang="scss">
  .wx_content_check{
    .el-row{margin-bottom:22px;}
    .label{margin-right:8px;font-size:14px;}
    .el-table td{padding:5px 0;vertical-align:top;}
    .el-tag{margin-left:10px;height:18px;line-height:16px;}
    .newsItem{
      &{margin-top:10px;overflow:hidden;}
      .preview{float:left;width:100px;height:100px;}
      .content{margin-left:110px;}
      .content a{color:inherit;text-decoration:none;}
    }
    .reason{display:block;color:#ccc;}
    .reason em{display:inline-block;max-width:104px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;vertical-align:middle;}
  }
</style>
